package process;

import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import entity.Subcase;

public class SubCaseProcess extends EntityProcess {

	public Collection<Subcase> getSubCasesByCase(Long id)throws Exception{
		EntityManager em = this.getEntityManager();
		try{			
			Query q = em.createQuery("SELECT p FROM "+Subcase.class.getName()+" p WHERE P.caseId=?1");
			q.setParameter(1, id);
			
		    @SuppressWarnings("unchecked")
			List<Subcase> results = q.getResultList();			
			return results;
		}
		catch(Exception ex){
			throw ex;//this.LogException(ex);
		}
		finally{
			this.releaseEntityManager(em);
		}
	}
	
	public void saveSubCases(Long caseId, Collection<Subcase> entities)throws Exception{
		Collection<Subcase> exists = this.getSubCasesByCase(caseId);
		this.saveEntities(caseId, entities, exists);
	}
}
